﻿namespace LeetCodeProject._0001_1000._101_200._101_110._101;

public class Solution
{
    public bool IsSymmetric(TreeNode root)
    {
        return IsEqual(root, root);
    }

    public bool IsEqual(TreeNode rootLeft, TreeNode rootRight)
    {
        if (rootLeft == null && rootRight == null)
        {
            return true;
        }

        if (rootLeft == null || rootRight == null || rootLeft.val != rootRight.val)
        {
            return false;
        }

        bool IsLeftEqual = IsEqual(rootLeft.left, rootRight.right);
        bool IsRightEqual = IsEqual(rootLeft.right, rootRight.left);
        return IsLeftEqual && IsRightEqual;
    }
}